
var V=new Vue({
    el:'#main',
    data:()=>({
        listdata:[],
        page:1,
        pageSize:10,
        sousuo:'',
        lang:"",
        title:1123,
        batch:[],
        allid:[]
    }),
    methods:{
        changefn(lang){
            this.lang=lang
        },
        requestSearch(){
            this.getdata()
        },
        getdata(valday){
            var data={
                page: this.page,
                    limit: this.pageSize,
                    lang: this.lang,
            }
            if(valday){
                data.day=valday
            }
            this.batch=[]
            $.ajax({
                url:'/admin/Proverify/list',
                data,
                type:'post',
                success:(data)=>{             
                    data = JSON.parse(data)
                    $('th input').prop('checked', false)                   
                    this.listdata=data.prodesc_cat    
                    this.allid=[] 
                    this.listdata.forEach(element => {
                        this.allid.push(element.prodesc_id)
                    });
                    if(data.size / this.pageSize>1){
                        $('#pagination').show()
                        this.setPage(data.page-0,data.size)
                    }else{
                        $('#pagination').hide()
                    }
                }
            })
        },
        setPage(pageCurrent, pageSum) {
            //数据总条数
            var myPageCount = pageSum;
            //一页显示多少条
            var myPageSize = this.pageSize;
            //总页数
            var countindex = myPageCount % myPageSize > 0 ? (myPageCount / myPageSize) + 1 : (myPageCount / myPageSize);
            $.jqPaginator('#pagination', {
                totalPages: parseInt(countindex),
                //最多显示多少页
                visiblePages: 5,
                //默认显示第几页
                currentPage: pageCurrent,
                first: '<li class="first"><a href="javascript:;">'+langcon.page_home+'</a></li>',
                prev: '<li class="prev"><a href="javascript:;"><i class="arrow arrow2"></i>'+langcon.previous_page+'</a></li>',
                next: '<li class="next"><a href="javascript:;">'+langcon.next_page+'<i class="arrow arrow3"></i></a></li>',
                last: '<li class="last"><a href="javascript:;">'+langcon.last_page+'</a></li>',
                page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
                all:'<li class="page"><a href="javascript:;">'+parseInt(countindex)+' / '+this.page+'PG , '+this.pageSize+' /PG</a></li>',
                onPageChange:(num, type)=>{
                    if (type == "change") {
                        this.page=num
                    }
                }
            });
        },
        threeDay(day){
            if(day){
                this.getdata(day)
            }else{
                this.getdata(undefined)
            }
        },
        multiretract(){
            this.requestAjax(this.batch,'/admin/Proverify/verifyopen?request=verify',true);
        },
        retract(id){
            var ids = [];
            ids.push(id);
            this.requestAjax(ids,'/admin/Proverify/verifyopen?request=verify',true);
        },
        multiverify(ids){
            this.requestAjax(this.batch,'/admin/Proverify/verifyopen?request=verify');
        },
        requestAjax(ids,url,retract=false){
            $.ajax({
                url: url,
                type: 'post',
                data:{id:ids,retract:retract},
                success: function (data) {             
                    data = JSON.parse(data)
                    change_mes_type('.alert',data.status)
                    if(data.status==1){
                        $('.alert').show()
                        $('.alert p').html('*'+data.msg+'<br>')
                        $('#procat_editModal').modal('hide')
                    }else{
                        $('.alert').show()
                        $('.alert p').html('*'+data.msg+'<br>')
                        state=true
                    }
                }
            })
        },
        onesel(did){
            if (this.batch.indexOf(did) == -1) {
                this.batch.push(did)
            } else {
                this.batch.splice(this.batch.indexOf(did), 1)
            }
            var isall = true
            $('td input').each(function () {
                if (!$(this).prop('checked')) {
                    isall = false
                }
            })
            $('th input').prop('checked', isall)
        },
        //全选
        allsel(event){
            if ($(event.target).prop('checked')) {
                $(event.target).parents('table').find('input').prop('checked', true)
                this.batch = this.allid
            } else {
                $(event.target).parents('table').find('input').prop('checked', false)
                this.batch = []
            }
        }
    },
    mounted(){
        this.getdata()
        $('#prointro_verifyModal').on('hidden.bs.modal',(e)=>{
            this.getdata()
          })
    },
    watch:{
        lang:function(){
            this.getdata()
        }
    }
})